<?php
class clsMetatags {
	private $conn;
	public function __construct() {
		$this->conn = connectorFactory::conexao ();
	}
	public static function deletar($tabela, $valores) {
		$dao = new clsDao ();
		
		$IDMET = $dao->registro ( $tabela, 'IDMET', $valores );
		$valores ['IDMET'] = $IDMET;
		if ($IDMET) {
			$dao->deletar ( $tabela, $valores );
			
			$where2 ['IDLOJ'] = IDLOJ;
			$where2 ['IDMET'] = $IDMET;
			$dao->deletar ( 'metatags', $where2 );
		}
	}
	public static function postar($campo, $tabela, $valores) {
		$dao = new clsDao ();
		if ($tabela != '' && $valores != '') {
			if ($_POST [$campo . 'SEO'] [title] != '' || $_POST [$campo . 'SEO'] [desc] != '' || $_POST [$campo . 'SEO'] [key] != '') {
				$IDMET = $dao->registro ( $tabela, 'IDMET', $valores );
				$a ['IDLOJ'] = IDLOJ;
				$where = $a;
				if ($IDMET == '') {
					$metatags ['IDLOJ'] = IDLOJ;
					$a ['IDMET'] = $IDMET = $dao->ultimoRegistro ( 'metatags', 'IDMET', $metatags );
				} else
					$a ['IDMET'] = $IDMET;
				
				$w = $w2 = $a;
				
				$a ['TITLE'] = $_POST [$campo . 'SEO'] [title];
				$a ['DESCRIPTION'] = $_POST [$campo . 'SEO'] [desc];
				$a ['KEYWORDS'] = $_POST [$campo . 'SEO'] [key];
				
				$dao->completo ( 'metatags', $a, $w );
				$w2 ['IDMET'] = $valores ['IDMET'] = $IDMET;
				$s = $dao->completo ( $tabela, $valores, $w2, true );
			} else {
				$registro = $dao->registro ( $tabela, 'IDMET', $valores );
				$dao->deletar ( $tabela, $valores );
				
				$where ['IDLOJ'] = IDLOJ;
				$where ['IDMET'] = $registro;
				if ($registro != '')
					$dao->deletar ( 'metatags', $where );
			}
		}
	}
	public function valores($tabela, $valores) {
		$valores ['IDLOJ'] = IDLOJ;
		$dao = new clsDao ();
		$registro = $dao->registro ( $tabela, 'IDMET', $valores );
		if ($registro != '') {
			$rs = $this->conn->execute ( $sql = 'SELECT * FROM metatags WHERE "IDLOJ" = \'' . IDLOJ . '\' AND "IDMET" = \'' . $registro . '\' ' );
			$val [0] = $rs->fields ['IDMET'];
			$val [1] = $rs->fields ['TITLE'];
			$val [2] = $rs->fields ['DESCRIPTION'];
			$val [3] = $rs->fields ['KEYWORDS'];
		}
		return $val;
	}
}

?>